home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 10
/
FM Towns Free Software Collection 10.iso
/
ms_dos
/
tool
/
dprint
/
dpatoi.c
< prev
next >
Wrap
Text File
|
1994-08-11
|
1KB
|
86 lines
/*
8086|Printman/POSTCARD 固定小数点数処理ルーチン
Copyright (c) 1993,94 Delmonta
*/
#include"dprint.h"
/*---------------------------------------------------------------------------*/
fract dpatoi(char *p)
{
char c;
bool sign = FALSE;
int h=0,l=0;
int i;
while ((c=*p)==' ')
p++;
if (c=='-')
{
sign = TRUE;
p++;
}
else if (c=='+')
{
sign = FALSE;
p++;
}
while ('0'<=(c=*(p++)) && c<='9')
{
h = h*10 + (c-'0');
if (h>326)
goto dpatoi_err;
}
if (c<=' ') /* コントロールコードもしくはスペース */
goto dpatoi_end;
else if (c!='.')
goto dpatoi_err;
i = 10;
while ('0'<=(c=*(p++)) && c<='9')
{
l = l + (c-'0')*i;
i = i/10;
}
if (c>' ')
goto dpatoi_err;
dpatoi_end:
i = h*100 + l;
if (sign)
i = -i;
return i;
dpatoi_err:
return DPATOI_ERROR;
}
/*---------------------------------------------------------------------------*/
char *putfract(char *buf,fract val)
{
int h,l;
if (val<0) h = -val;
else h = val;
l = h%100;
h = h/100;
if (val<0) h = -h;
sprintf(buf,"%4d.%02u",h,l);
return buf;
}